package net.qiqb.module.spring;

import net.qiqb.module.ModuleContext;
import net.qiqb.module.ModuleServiceConfig;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ModulePostProcessor implements InitializingBean, ApplicationContextAware {

    private ModuleContext moduleContext;

    @Override
    public void afterPropertiesSet() throws Exception {
        for (ModuleServiceConfig serviceConfig : moduleContext.getServiceConfigs()) {
            serviceConfig.init();
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        moduleContext = applicationContext.getBean(ModuleContext.class);
    }
}
